package softtech.apps.adapter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import softtech.apps.dangtinraovat.R;
import softtech.apps.model.Product;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ProductAdapter extends BaseAdapter{
	private static final String TAG = "ProductArrayAdapter";
	private List<Product> productList = new ArrayList<Product>();
	private Context mContext;
	public ProductAdapter(Context context,List<Product> lst) {
		// TODO Auto-generated constructor stub
		mContext = context;
		productList = lst;
	}
    static class UserViewHolder {
        ImageView productThumbnail;
        TextView productName;
        TextView timeCreate;
    }
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.productList.size();
	}

	@Override
	public Product getItem(int position) {
		// TODO Auto-generated method stub
		return this.productList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return this.productList.get(position).hashCode();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View row = convertView;
		UserViewHolder viewHolder;
		if (row == null) {
			LayoutInflater mInflater = (LayoutInflater) mContext
					.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			row = mInflater.inflate(R.layout.productlist_item, null);
            viewHolder = new UserViewHolder();
            viewHolder.productThumbnail = (ImageView) row.findViewById(R.id.imgProductThumbnail);
            viewHolder.productName = (TextView) row.findViewById(R.id.tvProductName);
            viewHolder.timeCreate = (TextView) row.findViewById(R.id.tvTimeCreate);
            row.setTag(viewHolder);
		} else {
            viewHolder = (UserViewHolder)row.getTag();
        }
		Product product = getItem(position);
		// Set lai avatar cho user
		viewHolder.productThumbnail.setImageResource(R.drawable.ic_launcher);
		viewHolder.productName.setText(product.getpName());
		viewHolder.timeCreate.setText(product.getpTimeCreate());
		return row;
	}

}
